

function saveDocument(){
    var type = "file";          //后台接收时需要的参数名称，自定义即可
    var id = "cert";            //即input的id，用来寻找值
    var formData = new FormData();
	
    var title = $("#title").val();
    if(title == ""){
        alert("标题不能为空");
        return ;
    }
    var content = $("#content").val();
    if(content == ""){
        alert("内容不能为空");
        return ;
    }	
    var peerReviewer = $("#peerReviewer").val();
    if(peerReviewer == ""){
        alert("审稿人不能为空");
        return ;
    }	
    var draftingDepartment = $("#draftingDepartment").val();
    if(draftingDepartment == ""){
        alert("起草部门不能为空");
        return ;
    }	
    var mainUnit = $("#mainUnit").val();
    if(mainUnit == ""){
        alert("主送外单位不能为空");
        return ;
    }
    var copyUnit = $("#copyUnit").val();
    if(copyUnit == ""){
        alert("抄送外单位不能为空");
        return ;
    }

    var participateList = $("input[name='participate']");
    var participateTemp = "";

    for(var i=0; i<participateList.length; i++){
        if(participateList[i].value != ""){
            if(participateTemp == ""){
                participateTemp = participateList[i].value;
            }else {
                participateTemp = participateTemp + "," +participateList[i].value;
            }
        }
    }

    formData.append("title",title);
    formData.append("content",content);
    formData.append("peerReviewer",peerReviewer);
    formData.append("draftingDepartment",draftingDepartment);
	formData.append("mainUnit",mainUnit);
	formData.append("copyUnit",copyUnit);
    formData.append("file1", $("#file1")[0].files[0]);    //生成一对表单属性
    formData.append("file2", $("#file2")[0].files[0]);    //生成一对表单属性

    formData.append("participateTemp",participateTemp);

    $.ajax({
        type: "POST",           //因为是传输文件，所以必须是post
        url: 'http://localhost:8080/yd/document/saveAndFile',         //对应的后台处理类的地址
        data: formData,
        processData: false,
        contentType: false,
        headers:
        {
            "token": cookie.get("token")
        },
        success: function (data) {
            if(data.message == "无token，请重新登录" || data.message == "凭证过期,请重新登录" ){
                errorAjax();
            }else{
                window.location.href='document.html'
            }
        }
    });
}
// 添加审批人
function addParticipate() {
    $("#participateList").append("<div class=\"form-group\"><label class=\"col-sm-2 control-label\">参与者：</label><div class=\"col-sm-10\"><input type=\"text\" class=\"form-control\" name=\"participate\" required=\"\"></div></div>");
}

//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d +' '+h+':'+minute;
};